import React, { Component } from 'react';

export default class App extends Component {
  constructor(props) {
    super(props)

    this.state = {
      counter: 0,
      message: 'Hello World'
    }
  }

  render() {
    console.log('App render')
    return (
      <div>
        <h2>current count: {this.state.counter}</h2>
        <button onClick={ e => this.incrment() }>+1</button>
        <button onClick={ e => this.decrment() }>-1</button>
        <h2>message: {this.state.message}</h2>
        <input onInput={ e => this.changeText(e) } />
      </div>
    )
  }

  shouldComponentUpdate(nextProps, nextState) {
    if (this.state.counter !== nextState.counter) {
      return true
    }
    return false
  }

  incrment() {
    this.setState({
      counter: this.state.counter + 1
    })
  }

  decrment() {
    this.setState({
      counter: this.state.counter - 1
    })
  }

  changeText(e) {
    this.setState({
      message: e.target.value
    })
  }
}